<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>加加减减</title>
</head>

<body>
  <!-- 创建一个容器 -->
  <div id="app">
    <ul>
      <li v-for="(item, index) in arr" :key="index">
        {{item}}
        <button @click="del(item)">删除</button>
      </li>

    </ul>
    <button @click="add">生成</button>
  </div>
  <!-- 2.引入Vue.js -->
  <script src="./js/vue-2.7.14.js"></script>
  <!-- 3.实例化Vue对象 -->
  <script>
    let app = new Vue({
      el: '#app',
      data: {
        num: 0,
        arr: []
      },
      methods: {
        add() {
          this.num = Math.floor(Math.random() * 20)
          this.arr.push(this.num)
          console.log(this.arr);
        },
        del(item) {
          this.arr = this.arr.filter(a => {
            return a !== item
          })
        }
      }
    })
  </script>
</body>

</html>